import 'package:flutter/material.dart';
import 'package:hi_net/page/ranking_tab_page.dart';
import 'package:hi_net/util/view_util.dart';
import 'package:hi_net/widget/hi_navigation_bar.dart';
import 'package:hi_net/widget/hi_tab.dart';

///排行
class RankingPage extends StatefulWidget {
  const RankingPage({super.key});

  @override
  State<RankingPage> createState() => _RankingPageState();
}

class _RankingPageState extends State<RankingPage> with TickerProviderStateMixin {
  static const tabs = [
    {"key": "like", "name": "最热"},
    {"key": "pubdate", "name": "最新"},
    {"key": "favorite", "name": "收藏"}
  ];

  late TabController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TabController(length: tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          _buildNavigationBar(),
          _buildTabView(),
        ],
      ),
    );
  }

  _buildNavigationBar() {
    return HiNavigationBar(
      child: Container(
        alignment: Alignment.center,
        child: _tabBar(),
        decoration: bottomBoxShadow(),
      ),
    );
  }

  _tabBar() {
    return HiTab(
      tabs.map((tab) {
        return Tab(text: tab['name']);
      }).toList(),
      fontSize: 16,
      borderWidth: 2,
      unselectedLabelColor: Colors.black54,
      controller: _controller,
    );
  }

  _buildTabView() {
    return Flexible(
        child: TabBarView(
      controller: _controller,
      children: tabs.map((tab) {
        return RankingTabPage(sort: tab['key'] ?? '');
      }).toList(),
    ));
  }
}
